﻿using System;
using Moq;
using NBehave.Spec.NUnit;
using NUnit.Framework;

namespace SilverlightCalculator.Tests
{
    [TestFixture]
    public class When_using_the_CalculatorViewModel
    {
        private Mock<ICalculator> _calculator;
        private Mock<ICalculatorValidator> _calculatorValidator;
        private CalculatorViewModel _calculatorViewModel;

        [SetUp]
        public void SetUp()
        {
            _calculator = new Mock<ICalculator>();
            _calculatorValidator = new Mock<ICalculatorValidator>();
            _calculatorViewModel = new CalculatorViewModel(_calculator.Object, _calculatorValidator.Object);
        }

        [Test]
        public void Initial_value_of_first_number_is_0()
        {
            // Arrange
            // done is setup 

            // Act
            var result = _calculatorViewModel.FirstValue;

            // Assert
            result.ShouldEqual("0");
        }

        [Test]
        public void Initial_value_of_second_number_is_0()
        {
            // Arrange
            // done is setup 

            // Act
            var result = _calculatorViewModel.SecondValue;

            // Assert
            result.ShouldEqual("0");
        }

        [Test]
        public void Initial_value_of_calculate_button_is_enabled()
        {
            // Arrange
            // done is setup 

            // Act
            var result = _calculatorViewModel.CalculateCommand.IsEnabled;

            // Assert
            result.ShouldBeTrue();
        }


        [Test]
        public void Calculate_command_should_not_be_enabled_if_ViewModel_contains_an_error()
        {
            // Arrange
            // done is setup           

            // Act
            _calculatorViewModel.AddErrorForProperty("X", "X");

            // Assert 
            _calculatorViewModel.CalculateCommand.IsEnabled.ShouldBeFalse();
        }
    }
}